package com.zusmart.core.config.support;

import com.zusmart.core.config.ConfigData;
import com.zusmart.core.config.ConfigDataType;

public class AbstractConfigData<T> implements ConfigData<T> {

	protected T data;
	protected ConfigDataType type;

	protected AbstractConfigData(T data, ConfigDataType type) {
		if (null == type) {
			throw new IllegalArgumentException("config data type must not be null");
		}
		this.data = data;
		this.type = type;
	}

	@Override
	public T getData() {
		return this.data;
	}

	@Override
	public ConfigDataType geSourceDataType() {
		return this.type;
	}

	@Override
	public boolean isExpression() {
		return this.type == ConfigDataType.Expression;
	}

	@Override
	public boolean isArgument() {
		return this.type == ConfigDataType.Argument;
	}

	@Override
	public boolean isDefinition() {
		return this.type == ConfigDataType.Definition;
	}

	@Override
	public boolean isNotFound() {
		return this.type == ConfigDataType.NotFound;
	}

	@Override
	public int hashCode() {
		return this.toString().hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (null == obj) {
			return false;
		}
		if (obj instanceof AbstractConfigData) {
			return obj.toString().equals(this.toString());
		}
		return false;
	}

	@Override
	public String toString() {
		return String.format("[ConfigData]%s", this.data);
	}

}